package com.nsgf.library.ui.adapter;

import android.content.Context;

import androidx.recyclerview.widget.DiffUtil;
import androidx.recyclerview.widget.RecyclerView;

import com.kunminx.binding_recyclerview.adapter.SimpleDataBindingAdapter;
import com.nsgf.library.R;
import com.nsgf.library.data.bean.AnnouncementBean;
import com.nsgf.library.databinding.ItemNoticeAnnouncementBinding;

/**
 * 通知公告列表适配器
 */
public class NoticeAnnouncementAdapter extends SimpleDataBindingAdapter<AnnouncementBean.RecordBean, ItemNoticeAnnouncementBinding> {

    public NoticeAnnouncementAdapter(Context context) {
        super(context, R.layout.item_notice_announcement, new DiffUtil.ItemCallback<AnnouncementBean.RecordBean>() {
            @Override
            public boolean areItemsTheSame(AnnouncementBean.RecordBean oldItem, AnnouncementBean.RecordBean newItem) {
                return oldItem.getId() == newItem.getId();
            }

            @Override
            public boolean areContentsTheSame(AnnouncementBean.RecordBean oldItem, AnnouncementBean.RecordBean newItem) {
                return oldItem.getId() == newItem.getId() &&
                        (oldItem.getAnnouncementTopic() != null ? oldItem.getAnnouncementTopic().equals(newItem.getAnnouncementTopic()) : newItem.getAnnouncementTopic() == null) &&
                        (oldItem.getDescription() != null ? oldItem.getDescription().equals(newItem.getDescription()) : newItem.getDescription() == null) &&
                        oldItem.getIsRead() == newItem.getIsRead();
            }
        });
    }

    @Override
    protected void onBindItem(ItemNoticeAnnouncementBinding binding, AnnouncementBean.RecordBean item, RecyclerView.ViewHolder holder) {
        binding.setVm(item);
    }
}

